import { requestDetailList } from "@/api"
//detail模块的vuex配置
const state ={
    detailList:{}
}
const mutations ={
    SET_DETAILLIST_STATE(state,value){
        state.detailList = value
    }
}
const actions={
  async  getDetailList({commit},skuId){
        const result = await requestDetailList(skuId)
        commit("SET_DETAILLIST_STATE",result)
    }
}
const getters={
    categoryView(state){
        //因为请求是异步的，当detailList中还没有数据时，那么categoryView的值就为undefined，此时在详情页中用categoryView中的值就会报错，所以要给categoryView赋一个初始值空对象，这样就不会报错了
        return state.detailList.categoryView || {}
    },
    spuSaleAttrList(){
        return state.detailList.spuSaleAttrList || []
    },
    skuInfo(){
        return state.detailList.skuInfo || {}
    }

}

export default {
    namespaced:true,
    state,
    mutations,
    actions,
    getters
}